<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function delay(duration, n) {
            return new Promise((resolve) => {
                setTimeout(() => {
                    resolve(n);
                }, duration)
            })
        }

        // 函数内部有 await 前面必须添加 async
        // 因为 await 是可以让异步变同步 为了不让其执行时间过长/还具有异步的效果 那么前面就必须添加 async
        async function fn() {
            const n1 = await delay(2000, 1);
            console.log(n1);
            const n2 = await delay(1000, 3);
            console.log(n2);
            const n3 = await delay(1000, 2);
            console.log(n3);
        }
        fn()
    </script>
</body>
</html>